home *** CD-ROM | disk | FTP | other *** search
/ Collection of Tools & Utilities / Collection of Tools and Utilities.iso / c / jpl_c.zip / BITCOUNT.C < prev    next >
Text File  |  1986-05-18  |  768b  |  29 lines

  1. /* 1.0  07-06-84 
  2.  ************************************************************************
  3.  *            Robert C. Tausworthe                *
  4.  *            Jet Propulsion Laboratory            *
  5.  *            Pasadena, CA 91009        1984        *
  6.  ************************************************************************
  7.  *
  8.  *    This is the bitcount(n) function in Kernighan and Ritchie, on
  9.  *    page 47.
  10.  */
  11.  
  12. #include "defs.h"
  13. #include "stdtyp.h"
  14.  
  15. /************************************************************************/
  16.  
  17. bitcount(n)        /* count number of 1-bits in n            */
  18.  
  19. /*----------------------------------------------------------------------*/
  20. BITS n;
  21. {
  22.     int b;
  23.  
  24.     for (b = 0; n ISNT 0; n >>= 1)
  25.         if (n & 01)
  26.             b++;
  27.     return (b);
  28. }
  29.